package org.dromara.system.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SysFaultFeedbackAuditBo;
import org.dromara.system.domain.bo.SysFaultFeedbackQueryBo;
import org.dromara.system.domain.vo.SysFaultFeedbackVo;
import org.dromara.system.service.ISysFaultFeedbackService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 故障反馈管理（管理端） 控制层
 *
 * @author system
 * @date 2025-10-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/faultFeedback")
public class SysFaultFeedbackController extends BaseController {

    private final ISysFaultFeedbackService feedbackService;

    /**
     * 查询故障反馈列表（管理端）
     */
    @SaCheckPermission("system:faultFeedback:list")
    @GetMapping("/list")
    public TableDataInfo<SysFaultFeedbackVo> list(
        SysFaultFeedbackQueryBo queryBo, PageQuery pageQuery) {
        return feedbackService.queryPageList(queryBo, pageQuery);
    }

    /**
     * 查询故障反馈详情
     */
    @SaCheckPermission("system:faultFeedback:query")
    @GetMapping("/{feedbackId}")
    public R<SysFaultFeedbackVo> getInfo(
        @NotNull(message = "反馈ID不能为空") @PathVariable Long feedbackId) {
        SysFaultFeedbackVo vo = feedbackService.queryById(feedbackId);
        return R.ok(vo);
    }

    /**
     * 审核故障反馈
     */
    @SaCheckPermission("system:faultFeedback:audit")
    @Log(title = "故障反馈审核", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public R<Void> audit(@Validated @RequestBody SysFaultFeedbackAuditBo auditBo) {
        boolean result = feedbackService.auditFeedback(auditBo);
        return toAjax(result);
    }

    /**
     * 导出故障反馈列表
     */
    @SaCheckPermission("system:faultFeedback:export")
    @Log(title = "故障反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysFaultFeedbackQueryBo queryBo, HttpServletResponse response) {
        List<SysFaultFeedbackVo> list = feedbackService.queryList(queryBo);
        ExcelUtil.exportExcel(list, "故障反馈", SysFaultFeedbackVo.class, response);
    }

}

